package com.dzsw.comb;

import java.util.Arrays;
import java.util.LinkedList;

public class CombMain {

    public static void recursionSub(LinkedList<String[]> list, int count, String[] array,
                                    int ind, int start, int... indexs) {
        start++;
        if (start > count - 1) {
            return;
        }
        if (start == 0) {
            indexs = new int[array.length];
        }
        for (indexs[start] = ind; indexs[start] < array.length; indexs[start]++) {
            recursionSub(list, count, array, indexs[start] + 1, start, indexs);
            if (start == count - 1) {
                String[] temp = new String[count];
                for (int i = count - 1; i >= 0; i--) {
                    temp[start - i] = array[indexs[start - i]];
                }
                list.add(temp);
            }
        }
    }

    public static void main(String[] args) {
        String string = "abcdefghijklmnopqrst";
        String[] A = string.split("(?!\\b)");
        LinkedList<String[]> list = new LinkedList<String[]>();
        recursionSub(list, 4, A, 0, -1);
        for (String[] strings : list) {
            System.out.println(Arrays.toString(strings).replaceAll("[\\[\\]\\s,]", ""));
        }
        System.out.println("共有：" + list.size());
    }
}
